package com.ecity.table 
{
	import com.ecity.util.BitmapClip;
	import com.ecity.util.UIFactory;
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import gs.TweenLite;
	/**
	 * ...
	 * @author yicheng.zhang
	 */
	public class Player extends TableDisplayObject {
		private var bodyLayer:Sprite;
		private var headLayer:Sprite;
		private var faceLayer:Sprite;
		
		private var bloodPng:Bitmap;
		
		private var player:BitmapClip;
		private var isForward:Boolean;
		public static const GIRL:String = "girl";
		public static const BOY:String = "boy";
		public static const LADY:String = "lady";
		public static const MAN:String = "man";
		public static const GIGI:String = "gigi";
		public static const MDM:String = "mdm";
		public static const ROLES:Array = [MAN,GIRL,BOY,LADY,GIGI,MDM];
		private var bLayer:Sprite;
		
		
		public function Player(role:int = 0) {
			isForward = false;
			weave(ROLES[role]);
		}
		
		public function weave(role:String):void {
			player = new BitmapClip(role);
			player.x = -150;
			player.y = -210;
			bodyLayer = this.getLayer("body");
			bodyLayer.addChild(player);
			smile();
		}
		
		public function smile():void {
			player.gotoAndPlay(13,28);
		}
		
		public function surprise():void {
			player.gotoAndPlay(1,12);
		}
		
		public function tight():void {
			player.gotoAndPlay(29,45);
		}
		
		public function blood():void {
			player.stop();
			bloodPng = UIFactory.getBitmapbyName("blood") as Bitmap;
			bloodPng.x = player.x-200;
			bloodPng.y = player.y-80;
			bLayer = this.getLayer("blood");
			bLayer.addChild(bloodPng);
		}
		
		public function clearBlood():void {
			this.smile();
			bLayer.removeChild(bloodPng);
		}
		
		public function forward():void {
			if (!isForward) {
				var moveY:Number = bodyLayer.y-100;
				TweenLite.to(bodyLayer, 1, { x:0, y: moveY } );
				isForward = true;
			}
		}
		public function backward():void {
			if (isForward) {
				var moveY:Number = bodyLayer.y+100;
				TweenLite.to(bodyLayer,1,{x:0,y:moveY});
				isForward = false;
				this.smile();
			}
		}

		
	}

}